<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('拦截修改')"/>
</head>
<body>
<form action="" class="layui-form" th:object="${SysInterUrl}">
    <div class="mainBox">
        <div class="main-container">
            <div class="main-container">
                <div class="layui-form-item layui-hide">
                    <label class="layui-form-label">编号</label>
                    <div class="layui-input-block">
                        <input autocomplete="off" class="layui-input" lay-verify="title" name="id"
                               th:value="*{id}" type="text">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">拦截名称</label>
                    <div class="layui-input-block">
                        <input autocomplete="off" class="layui-input" lay-verify="interName" name="interName"
                               placeholder="拦截名称" th:value="*{interName}" type="text">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">拦截URL</label>
                    <div class="layui-input-block">
                        <input autocomplete="off" class="layui-input" name="url" placeholder="拦截URL" th:value="*{url}"
                               type="text">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">类型</label>
                    <div class="layui-input-block">
                        <select id="type" name="type" th:field="*{type}"
                                th:with="type=${@dict.getType('sys_inter_url_type')}">
                            <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                    th:value="${dict.dictValue}"></option>
                        </select>
                    </div>
                </div>

            </div>
        </div>
    </div>
    <div class="bottom">
        <div class="button-container">
            <button class="layui-btn layui-btn-normal layui-btn-sm" lay-filter="position-update" lay-submit=""
                    type="submit">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
            <button class="layui-btn layui-btn-primary layui-btn-sm" type="reset">
                <i class="layui-icon layui-icon-refresh"></i>
                重置
            </button>
        </div>
    </div>
</form>
<th:block th:include="include :: footer"/>
<script>
    layui.use(['form', 'jquery'], function () {
        var form = layui.form;
        var $ = layui.jquery;
        var dtree = layui.dtree;
        var MODULE_PATH = rootPath + "/SysInterUrlController";
        //名称验证
        form.verify({
            interName: function (value) {
                if (value.length < 2) {
                    return '标题至少得2个字符啊';
                }
                var msg = "";
                $.ajax({
                    url: MODULE_PATH + '/checkNameUnique',
                    data: "interName=" + value,
                    dataType: 'json',
                    type: 'post',
                    async: false,
                    success: function (result) {
                        msg = result;
                    }
                });
                if (msg == 1) {
                    return "已有相同数据";
                }

            }
        });

        form.on('submit(position-update)', function (data) {
            $.ajax({
                url: MODULE_PATH + '/edit',
                data: data.field,
                dataType: 'json',
                contentType: 'application/x-www-form-urlencoded',
                type: 'post',
                success: function (result) {
                    if (result.code == 200) {
                        layer.msg(result.msg, {icon: 1, time: 1000}, function () {
                            parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页
                            parent.layui.table.reload("sysInterUrl-table");
                        });
                    } else {
                        layer.msg(result.msg, {icon: 2, time: 1000});
                    }
                }
            })
            return false;
        });
    })
</script>
<script>
</script>
</body>
</html>